/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_BASE_MUTEX_H_
#define SHARED_BASE_MUTEX_H_

#include "Global_Macros.h"

#ifdef __WIN32__
#include "Shared/Base/Mutex_WIN32.h"
#else
#error
#endif


class Mutex: private MutexImpl
{
public:
	Mutex(void);
	~Mutex(void);

	bool lock(void);
	bool lock(long milliseconds);
	bool tryLock(void);
	bool tryLock(long milliseconds);
	void unlock(void);

	bool isLocked(void) const;

private:
	DISALLOW_COPY_AND_ASSIGN(Mutex);
};


inline bool Mutex::lock(void)
{
	return lockImpl();
}

inline bool Mutex::lock(long milliseconds)
{
	return tryLockImpl(milliseconds);
}

inline bool Mutex::tryLock(void)
{
	return tryLockImpl();
}

inline bool Mutex::tryLock(long milliseconds)
{
	return tryLockImpl(milliseconds);
}

inline void Mutex::unlock(void)
{
	unlockImpl();
}

inline bool Mutex::isLocked(void) const
{
	return isLockedImpl();
}

#endif /* SHARED_BASE_MUTEX_H_ */
